package com.microstation.common;

import com.microstation.enums.ResultEnum;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Data
public class Result implements Serializable {
    private List<?> rows;
    private Integer errCode = 0;
    private Object object;
    private Map<String, Object> data;
    private Long results;
    private boolean hasError;
    private String error;
    private String errType;
    private String errUrl;

    public Result() {
        super();
    }


    public Result(Long results, List<?> rows) {
        this.hasError = Boolean.FALSE;
        this.error = null;
        this.results = results;
        this.rows = rows;
    }

    public Result(boolean hasError, String error) {
        this.hasError = hasError;
        this.error = error;
        if (hasError) {
            this.results = 0L;
            this.rows = null;
        }
    }


    public Result(boolean hasError, ResultEnum resultEnum, String errUrl) {
        this.hasError = hasError;
        this.errType = resultEnum.getType();
        this.error = resultEnum.getInfo();
        this.errUrl = errUrl;
    }

    public Result(boolean hasError, String errType, String error, String errUrl) {
        this.hasError = hasError;
        this.errType = errType;
        this.error = error;
        this.errUrl = errUrl;
    }

    public Result(String errType, Object object) {
        this.hasError = Boolean.FALSE;
        this.errType = errType;
        this.object = object;
    }

    public Result(boolean hasError, ResultEnum resultEnum, Object object) {
        this.hasError = hasError;
        this.errType = resultEnum.getType();
        this.error = resultEnum.getInfo();
        this.object = object;
    }

    public Result(boolean hasError, ResultEnum resultEnum, Object object,String errUrl) {
        this.hasError = hasError;
        this.errType = resultEnum.getType();
        this.error = resultEnum.getInfo();
        this.object = object;
        this.errUrl = errUrl;
    }

    public Result(boolean hasError, String errType, Object object) {
        this.hasError = hasError;
        this.errType = errType;
        this.object = object;
    }

    public Result(boolean hasError, String error, String errType, String errUrl, Long results, List<?> rows,
                  Object object) {
        super();
        this.rows = rows;
        this.object = object;
        this.results = results;
        this.hasError = hasError;
        this.error = error;
        this.errType = errType;
        this.errUrl = errUrl;
    }

    public void setResultEnum(ResultEnum resultEnum) {
        this.setErrType(resultEnum.getType());
        this.setError(resultEnum.getInfo());
    }

    public void setResultEnum(ResultEnum resultEnum, String error) {
        this.setErrType(resultEnum.getType());
        this.setError(error);
    }
}
